package com.bullsora.kindlerss.repository;

import com.bullsora.kindlerss.model.Subscription;
import com.bullsora.kindlerss.model.User;
import com.googlecode.objectify.Key;

/**
 * @author sorin.buliarca@iquesint.com
 */
public class UserRepository {

  private GenericOperations genericOperations;

  public GenericOperations getGenericOperations() {
    return genericOperations;
  }

  public void setGenericOperations(GenericOperations genericOperations) {
    this.genericOperations = genericOperations;
  }

  public User findUserByKindleAccount(String kindleUser) {
    return genericOperations.getObjectify().query(User.class).filter("kindleAccount", kindleUser).get();
  }

  public Iterable<Key<Subscription>> getUserSubscriptions(User user) {
    return genericOperations.getObjectify().query(Subscription.class).filter("userId", user.getId()).fetchKeys();
  }

}
